package cn.dyn.funchat.utils;

import org.slf4j.MDC;
import org.springframework.util.StringUtils;

public class TraceIdUtil {
    public static final String TRACE_ID = "traceId";

    public static void putTraceId() {
        String traceId = MDC.get(TRACE_ID);
        if (!StringUtils.hasText(traceId)) {
            traceId = NanoIdUtil.randomNanoId(20);
        }
        MDC.put(TRACE_ID, traceId);
    }

    public static void putTraceId(String traceId) {
        if (!StringUtils.hasText(traceId)) {
            traceId = NanoIdUtil.randomNanoId(20);
        }
        MDC.put(TRACE_ID, traceId);
    }
    public static String gutTraceId() {
        return MDC.get(TRACE_ID);
    }
}
